package com.qk.controller;

import com.qk.Response.PageResult;
import com.qk.Response.Result;
import com.qk.dto.CoursePageDTO;
import com.qk.entity.Course;
import com.qk.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @GetMapping
    public Result getPageCourses(CoursePageDTO coursePageDTO){
        log.info("查询课程列表：{}",coursePageDTO);
        PageResult<Course> pageResult =courseService.getPageCourses(coursePageDTO);
        return Result.success(pageResult);
    }
    /*
    添加课程
     */
    @PostMapping
    public Result addCourse(@RequestBody Course course){
        log.info("添加课程：{}",course);
        courseService.addCourse(course);
        return Result.success();
    }
    /*
    删除课程
     */
    @DeleteMapping("/{id}")
    public Result deleteCourseById(@PathVariable Integer id){
        log.info("删除课程：{}",id);
        courseService.deleteCourseById(id);
        return Result.success();
    }
    /*
    更新课程
     */
    /*
    先根据id查询课程
     */
    @GetMapping("/{id}")
    public Result selectCourseById(@PathVariable Integer id){
        log.info("查询课程：{}",id);
        Course course = courseService.selectCourseById(id);
        return Result.success(course);
    }
    /*
    更新课程
     */
    @PutMapping
    public Result updateCourse(@RequestBody Course course){
        log.info("更新课程：{}",course);
        courseService.updateCourse(course);
        return Result.success();
    }

}
